package com.kxmall.web.controller.huishou;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.kxmall.common.annotation.RepeatSubmit;
import com.kxmall.common.annotation.Log;
import com.kxmall.common.core.controller.BaseController;
import com.kxmall.common.core.domain.PageQuery;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.core.validate.AddGroup;
import com.kxmall.common.core.validate.EditGroup;
import com.kxmall.common.enums.BusinessType;
import com.kxmall.common.utils.poi.ExcelUtil;
import com.kxmall.huishou.domain.vo.HsWasteSiteVo;
import com.kxmall.huishou.domain.bo.HsWasteSiteBo;
import com.kxmall.huishou.service.IHsWasteSiteService;
import com.kxmall.common.core.page.TableDataInfo;

/**
 * 废品回收站信息
 *
 * @author kxmall
 * @date 2023-11-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/huishou/wasteSite")
public class HsWasteSiteController extends BaseController {

    private final IHsWasteSiteService iHsWasteSiteService;

    /**
     * 查询废品回收站信息列表
     */
    @SaCheckPermission("huishou:wasteSite:list")
    @GetMapping("/list")
    public TableDataInfo<HsWasteSiteVo> list(HsWasteSiteBo bo, PageQuery pageQuery) {
        return iHsWasteSiteService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出废品回收站信息列表
     */
    @SaCheckPermission("huishou:wasteSite:export")
    @Log(title = "废品回收站信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HsWasteSiteBo bo, HttpServletResponse response) {
        List<HsWasteSiteVo> list = iHsWasteSiteService.queryList(bo);
        ExcelUtil.exportExcel(list, "废品回收站信息", HsWasteSiteVo.class, response);
    }

    /**
     * 获取废品回收站信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("huishou:wasteSite:query")
    @GetMapping("/{id}")
    public R<HsWasteSiteVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iHsWasteSiteService.queryById(id));
    }

    /**
     * 新增废品回收站信息
     */
    @SaCheckPermission("huishou:wasteSite:add")
    @Log(title = "废品回收站信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HsWasteSiteBo bo) {
        return toAjax(iHsWasteSiteService.insertByBo(bo));
    }

    /**
     * 修改废品回收站信息
     */
    @SaCheckPermission("huishou:wasteSite:edit")
    @Log(title = "废品回收站信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HsWasteSiteBo bo) {
        return toAjax(iHsWasteSiteService.updateByBo(bo));
    }

    /**
     * 删除废品回收站信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("huishou:wasteSite:remove")
    @Log(title = "废品回收站信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iHsWasteSiteService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
